package cn.jinjimi.app.modules.crm;

import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.domain.ServiceManager;
import cn.jinjimi.domain.store.ConfigStore;
import cn.jinjimi.app.entity.AppConfig.AppAlert;
import cn.jinjimi.app.entity.AppConfig.AppModule;
import cn.jinjimi.app.modules.IModule;

import java.util.concurrent.Callable;

import bolts.Task;

/**
 * Created by zhenhua on 17/1/4.
 */

public class CRM implements IModule<CRM.Config> {


    private Config mConfig;

    @Override
    public Config getConfig() {
        if(mConfig==null) {
            fetchConfig();
        }
        return mConfig;
    }

    private void fetchConfig() {

        Task.callInBackground(new Callable<AppModule>() {
            @Override
            public AppModule call() throws Exception {
                AppModule module = ServiceManager.getService(ConfigStore.class).fetchConfigOfModule(AppModule.ModuleCRM);
                if(module!=null && module.config!=null){
                    mConfig = GsonUtils.fromJson(module.config, Config.class);
                }
                return module;
            }
        });

    }

    public static class Config{
        public AppAlert alert;
    }
}
